package com.jk.testsql.aop;

import com.jk.testsql.constant.DataSourceTypeEnum;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DataSourceContextHolder {
    private static final ThreadLocal<DataSourceTypeEnum> DB_CONTEXT_LOCAL =new ThreadLocal<>();

    /**
     * 设置指定数据库到上下文
     * @param dbType 数据库类型
     */
    public static void setDbContextLocal(DataSourceTypeEnum dbType) {
        DB_CONTEXT_LOCAL.set(dbType);
        log.info("数据库切换至【{}】",dbType);
    }
    /**
     * 从上下文中获取当前数据库
     */
    public static DataSourceTypeEnum getDbContextLocal() {
        return DB_CONTEXT_LOCAL.get();
    }
    /**
     * 移除上下文
     */
    public static void toRemove() {
        DB_CONTEXT_LOCAL.remove();
    }
}

